//# sourceURL=inviteCompanyEmpDetail.js
layui.element.on('tab(login-user-tabs)', function (layui_obj) {
    var custom_obj = $('#tabTitles')[0].children[layui_obj.index].tabCustomObj;
    var inviteCompanyEmpDetail_fn = {
        initRender: function () {
            $('#inviteCompanyEmpDetail').attr('hasRender', true);
            cmsUtils.setContentTabHeight('inviteCompanyEmpContent', 50);
            if (custom_obj.id) {
                var url = '/inviteCompanyEmp/detail/'+custom_obj.id;
                $.get(url, function (data) {
                    console.log(data);
                    inviteCompanyEmpDetail_fn.setFormData(data);
                    $('#inviteCompanyEmpDetail-industry').attr('lay-verify', 'required');
                    $('#inviteCompanyEmpDetail-industry').attr('lay-verType', 'tips');
                    var pic = [];
                    pic.push(data.data.imgUrl);
                    picUtils.initPicBox('inviteCompanyEmpDetail-img-id', pic, false);
                });
                $('button[lay-filter="inviteCompanyEmpDetail-btn-modify"]').show();
            } else {
                $.get('/inviteCompany/currentCompany', function (data) {
                    $('#inviteCompanyEmpDetail-form-companyName').val(data.data);
                });
                $('button[lay-filter="inviteCompanyEmpDetail-btn-add"]').show();
                cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/0','inviteCompanyEmpDetail-industry','code','value');
                $('#inviteCompanyEmpDetail-industry').attr('lay-verify', 'required');
                $('#inviteCompanyEmpDetail-industry').attr('lay-verType', 'tips');
            }
            layui.form.render(null, 'inviteCompanyEmpDetail-form');
        },
        setFormData: function (data) {
            cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/0','inviteCompanyEmpDetail-industry','code','value');
            cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/1','inviteCompanyEmpDetail-jobTitle','code','value');
            cmsUtils.formDataBind('inviteCompanyEmpDetail-form', data.data);
            layui.form.render(null, 'inviteCompanyEmpDetail-form');
        },
        getFormData: function (data) {
            data.id = custom_obj.id;
            data.imgUrl = $('#inviteCompanyEmpDetail-img-id').find('img')[0].src;
            return data;
        },
        verifyForm: function () {
            var bool = formVerifyUtils.picFieldChecker('inviteCompanyEmpDetail-btn-id','inviteCompanyEmpDetail-img-id');
            return bool;
        },
        submitForm: function (post_params, action, index) {
            console.log(post_params);
            $.ajax({
                type: 'post',
                url: '/inviteCompanyEmp/update',
                data: post_params,
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.code == 200) {
                        switch (action) {
                            case 'close':
                                layui.element.tabDelete('login-user-tabs', 'tab-inviteCompanyEmpDetail');
                                custom_obj.list_fn.reload();
                                break;
                        }
                    } else {
                        layer.msg(data.msg ? data.msg : '保存失败', {anim: 6});
                    }
                }
            });
        }
    }
    //下拉框动态加载
    layui.form.on('select(inviteCompanyEmpDetail-industry)',function(data){
        $("#inviteCompanyEmpDetail-jobTitle").empty();
        $("#inviteCompanyEmpDetail-jobTitle").append("<option value=''></option>");
        cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/1?parentId='+data.value,'inviteCompanyEmpDetail-jobTitle','code','value');
    });
    if ($('#inviteCompanyEmpDetail')[0] && !$('#inviteCompanyEmpDetail').attr('hasRender')) {
        inviteCompanyEmpDetail_fn.initRender();
        // 设置页面高度
        $(window).resize(function() {
            cmsUtils.setContentTabHeight('inviteCompanyEmpDetailContent', 50);
        });
        //logo添加
        var option = {
            btn_id: 'inviteCompanyEmpDetail-btn-id',
            ul_id: 'inviteCompanyEmpDetail-img-id',
            max_file_count: 1
        }
        picUtils.uploadInit(0, option);
    }
    // 添加
    layui.form.on('submit(inviteCompanyEmpDetail-btn-add)', function (data) {
        layer.confirm('确定添加吗？', {
            btn:['确定', '取消']
        }, function (index) {
            inviteCompanyEmpDetail_fn.submitForm(inviteCompanyEmpDetail_fn.getFormData(data.field), 'close', index);
        });
    });
    // 修改
    layui.form.on('submit(inviteCompanyEmpDetail-btn-modify)', function (data) {
        var msg = '确定保存修改信息？';
        layer.confirm(msg, {
            btn:['确定', '取消']
        }, function (index) {
            inviteCompanyEmpDetail_fn.submitForm(inviteCompanyEmpDetail_fn.getFormData(data.field), 'close', index);
        });
    });
});